package com.tanhua.dubbo.api;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tanhua.dubbo.api.db.BlackListApi;
import com.tanhua.dubbo.api.mapper.BlackListMapper;
import com.tanhua.model.db.BlackList;
import com.tanhua.model.vo.PageResult;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

@DubboService
public class BlackListApiImpl implements BlackListApi {

    @Autowired
    private BlackListMapper blackListMapper;

    /**
     * 分页查询登录用户的黑名称列表数据
     *
     * @param page
     * @param pageSize
     * @param userId
     * @return
     */
    @Override
    public PageResult findPageByUserId(Long page, Long pageSize, Long userId) {
        //1. 设置分页参数
        Page pageParam = new Page(page, pageSize);
        //2. 构建查询条件
        LambdaQueryWrapper<BlackList> lqw = new LambdaQueryWrapper<>();
        lqw.eq(BlackList::getUserId, userId);
        //3. 分页查询
        Page blackListPage = blackListMapper.selectPage(pageParam, lqw);
        //4. 构建分页结果PageResult
        return new PageResult(page,pageSize, blackListPage.getTotal(), blackListPage.getRecords());
    }

    /**
     * 黑名单 移除
     *
     * @param userId
     * @param blackUserId
     */
    @Override
    public void remove(Long userId, Long blackUserId) {
        LambdaQueryWrapper<BlackList> lqw = new LambdaQueryWrapper<>();
        lqw.eq(BlackList::getUserId, userId);
        lqw.eq(BlackList::getBlackUserId, blackUserId);
        blackListMapper.delete(lqw);
    }
}
